<template>
  <div class="mapDiv">
    <div class="header">
      <div class="title3">
        <div class="title-left">
          <img src="@/assets/yujing.png" /><span>预警</span>
        </div>
        <div class="trangle" />
      </div>
    </div>
    <div class="warn">
      <div class="wenzi">
        <div class="num">
          <p>规划编制逾期数量</p>
          <p><span class="red">5</span>个</p>
        </div>
      </div>
      <div ref="chart2" class="bing" />
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      myChart: null,
    };
  },
  mounted() {
    this.getEchartData();
    window.addEventListener("resize", () => {
      this.myChart.resize();
    });
  },
  methods: {
    getEchartData() {
      this.myChart = this.$echarts.init(this.$refs.chart2);
      const option = {
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: true,
              fontSize: "16",
              fontWeight: "bold",
              position: "center",
              formatter: function (params) {
                // 默认显示第一个数据
                if (params.dataIndex === 1) {
                  return params.value;
                } else {
                  return "";
                }
              },
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "16",
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            color: ["#B0C4DE", "#4778c7"],
            data: [
              { value: 3, name: "aaa" },
              { value: 2, name: "bbb" },
            ],
          },
        ],
      };
      this.myChart.setOption(option);
    },
  },
};
</script>
<style lang="scss" scoped>
.mapDiv {
  position: relative;
  .header {
    width: 100%;
    height: 40px;
    .title3 {
      width: 35%;
      height: 100%;
      color: #fff;
      font-size: 18px;
      letter-spacing: 1px;
      display: flex;
      align-items: center;
      position: relative;
      .title-left {
        display: flex;
        background-color: #ffc000;
        height: 40px;
        width: calc(100% - 40px);
        padding: 10px;
        align-items: center;
      }
      img {
        width: 30px;
        height: 30px;
        margin-right: 10px;
      }
      .trangle {
        float: left;
        width: 0px;
        height: 0px;
        border-left: 40px solid #ffc000;
        border-top: 40px solid #ffc000;
        border-right: 40px solid transparent;
      }
    }
  }
  .warn {
    margin: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 60px);
    border: 1px dashed #ffc000;
    border-radius: 5px;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .wenzi {
      width: 40%;
      height: 100%;
      position: relative;
      .num {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        p {
          letter-spacing: 1px;
          text-align: center;
          font-size: 18px;
          color: #3b5880;
          font-weight: 700;
        }
      }

      .red {
        font-size: 24px;
        font-weight: 600;
        color: #4778c7;
      }
    }
    .bing {
      width: 60%;
      height: 100%;
    }
  }
}
</style>
